//
//  TwoCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/12.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "TwoCell.h"


@implementation TwoCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier segArray:(NSArray *)segArr dataModel:(KeOneModel *)dataModel countArr:(NSMutableArray *)countArr nameArr:(NSMutableArray *)nameArr
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.dataModel = dataModel;
        
//       self.ContArr = countArr;
        [self.ContArr addObjectsFromArray:countArr];
        self.nameArr = nameArr;
        

        
        _orageLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
        _orageLab.backgroundColor = [UIColor orangeColor];
        _orageLab.textColor = [UIColor whiteColor];
        _orageLab.font = [UIFont systemFontOfSize:14];
        _orageLab.text = @"   来访客户量化分析";
        [self addSubview:_orageLab];
        
        
        //分段控件
        _segmented = [[UISegmentedControl alloc] initWithItems:segArr];
       _segmented.selectedSegmentIndex = 0;//设置默认选择项索引
        _segmented.tintColor = [UIColor orangeColor];
        //有四种基本样式
        //   [segmented setTitle:@"" forSegmentAtIndex:2];//设置索引的题目
        //   [segmented setImage:[UIImage imageNamed:@""] forSegmentAtIndex:3];//设置指定索引的图片
        [_segmented addTarget:self action:@selector(segmented:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_segmented];
        [_segmented mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_orageLab.mas_bottom).with.offset(10);
            make.left.equalTo(self).with.offset(10);
            make.right.equalTo(self).with.offset(-10);
            make.height.mas_offset(20);
        }];
        
        
   
        _lineChart = [[ZFLineChart alloc] initWithFrame:CGRectMake(-40, 65,SCREEN_WIDTH+40, 220)];
        //self.lineChart.topicLabel.textColor = ZFBlack;
        self.lineChart.dataSource = self;
        self.lineChart.delegate = self;
        self.lineChart.isResetAxisLineMinValue = YES;
        self.lineChart.isShowXLineSeparate = YES;
        self.lineChart.isShowYLineSeparate = YES;
        self.lineChart.linePatternType = kLinePatternTypeForCurve;
        
        [self addSubview:self.lineChart];
        [self.lineChart strokePath];
        

        
        
        
    }
    return self;
}


-(NSMutableArray *)ContArr{
    if (_ContArr) {
        return _ContArr;
    }
    _ContArr = [NSMutableArray arrayWithCapacity:0];
    return _ContArr;
    
}


-(NSMutableArray *)nameArr{
    if (_nameArr) {
        return _nameArr;
    }
    _nameArr = [NSMutableArray arrayWithCapacity:0];
    return _nameArr;
    
}


#pragma mark - ZFGenericChartDataSource
- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
    return self.ContArr;
    return @[@"0", @"20%", @"8.9%", @"20%", @"5%", @"10%"];
}



- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
    return self.nameArr;
    
    return @[@"一年级", @"二年级", @"三年级", @"四年级", @"五年级", @"六年级"];
}


- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    //曲线的颜色
    return @[ZFLvColor];
    //return [];
}

- (CGFloat)axisLineMaxValueInGenericChart:(ZFGenericChart *)chart{
    
    if (self.dataModel.lhfx.day.max_data) {
        return [self.dataModel.lhfx.day.max_data intValue];
        
        }
    else{
        return 100;
    }
    
   // return 90;
}

/**
 *  组与组之间的间距(若不设置,默认为20.f)
 */
- (CGFloat)paddingForGroupsInLineChart:(ZFLineChart *)lineChart
{
    return 50.f;
}




//背景格格
- (NSUInteger)axisLineSectionCountInGenericChart:(ZFGenericChart *)chart{
    return 1;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



//分段控制器
-(void)segmented:(UISegmentedControl *)senge{
    
    //下面的这个代理方法 不用  可以删除整个代理
//    [self.detegate didWithSegmented:senge];
    
    NSInteger Index = senge.selectedSegmentIndex;
    
    NSLog(@"---------Index %ld", Index);
    if (Index == 0) {
        
       
        self.dataArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.day.data) {
            NSLog(@"第二个cell ----===========  %@",fdata.count);
            [self.dataArr addObject:fdata.count];
        }
        if (self.ContArr) {//这样每次删除之前的数组 从新添加 和下面 self.nameArr = nameArr（简便写法） 效果是一样的 这些这是为了测试 
            [self.ContArr removeAllObjects];
            [self.ContArr addObjectsFromArray:self.dataArr];
        }
//        self.ContArr = self.dataArr;
        
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.day.data) {
            NSLog(@"第二0000000  个cell ----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        
        [self.lineChart strokePath];
        
        NSLog(@"点击的是第1个");
    }else if (Index == 1){
        
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.zhou.data) {
            NSLog(@"第二个cell ----===========  %@",fdata.count);
            [dataArr addObject:fdata.count];
        }
        if (self.ContArr) {
            [self.ContArr removeAllObjects];
            [self.ContArr addObjectsFromArray:dataArr];
        }
//        self.ContArr = dataArr;
        
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.zhou.data) {
            NSLog(@"第二0000000  个cell ----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        
        
        NSLog(@"点击的是第2个");
    }else if (Index == 2){
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.month.data) {
            NSLog(@"第二个cell ----===========  %@",fdata.count);
            [dataArr addObject:fdata.count];
        }
        if (self.ContArr) {
            [self.ContArr removeAllObjects];
            [self.ContArr addObjectsFromArray:dataArr];
        }
//        self.ContArr = dataArr;
        
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.month.data) {
            NSLog(@"第二0000000  个cell ----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        
        NSLog(@"点击的是第3个");
    }else if (Index == 3){
        
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.jidu.data) {
            NSLog(@"第二个cell ----===========  %@",fdata.count);
            [dataArr addObject:fdata.count];
        }
        if (self.ContArr) {
            [self.ContArr removeAllObjects];
            [self.ContArr addObjectsFromArray:dataArr];
        }
//        self.ContArr = dataArr;
        
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.jidu.data) {
            NSLog(@"第二0000000  个cell ----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        
        NSLog(@"点击的是第4个");
    }else if (Index == 4) {
        
        
        NSMutableArray *dataArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.year.data) {
            NSLog(@"第二个cell ----===========  %@",fdata.count);
            [dataArr addObject:fdata.count];
        }
        if (self.ContArr) {
            [self.ContArr removeAllObjects];
            [self.ContArr addObjectsFromArray:dataArr];
        }
//        self.ContArr = dataArr;
        
        NSMutableArray *nameArr = [[NSMutableArray alloc] init];
        for (FDataOneModel *fdata in self.dataModel.lhfx.year.data) {
            NSLog(@"第二0000000  个cell ----===========  %@",fdata.name);
            [nameArr addObject:fdata.name];
        }
        self.nameArr = nameArr;
        [self.lineChart strokePath];
        
        NSLog(@"点击的是第5个");
    }else{
        
         NSLog(@"点击的是第6个");
    }

    
}


@end
